package com.lims.landInfo.action;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import javacommon.base.*;

import com.lims.landInfo.model.*;
import com.lims.landInfo.service.*;
import com.lims.landInfo.vo.query.*;

/**
 * @author zzh
 * @version 1.0
 * @since 1.0
 */
@SuppressWarnings({ "unchecked", "serial" })
public class GuaranteeAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	//forward paths
	protected static final String LIST_JSP= "/pages/landInfo/Guarantee/list.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/pages/landInfo/Guarantee/list.do";
	
	private GuaranteeManager guaranteeManager;
	
	private Guarantee guarantee;
	java.lang.String id = null;
	private String items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			guarantee = new Guarantee();
		} else {
			guarantee = (Guarantee)guaranteeManager.getById(id);
		}
	}
	
	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setGuaranteeManager(GuaranteeManager manager) {
		this.guaranteeManager = manager;
	}	
	
	public Object getModel() {
		return guarantee;
	}
	
	public void setObjid(java.lang.String val) {
		this.id = val;
	}

	public void setItems(String items) {
		this.items = items;
	}
	
	/** 进入list页面 */
	public String list() {
		return LIST_JSP;
	}
	

	/**执行搜索**/
	public String findList() {
		GuaranteeQuery query = newQuery(GuaranteeQuery.class,DEFAULT_SORT_COLUMNS);
		ListRange listRange = this.guaranteeManager.findRange(query);
		this.responseOutWithJson(listRange);
		return null;
	}
	
	/** 保存新增对象 */
	public String save() {
		guaranteeManager.save(guarantee);
		this.responseOutWithJson("{\"success\":true,\"msg\":\"保存成功\"}");
		return null;
	}
	
	/**保存更新对象*/
	public String update() {
		guaranteeManager.update(this.guarantee);
		this.responseOutWithJson("{\"success\":true,\"msg\":\"更新成功\"}");
		return null;
	}
	
	/**删除对象*/
	public String delete() {
		String[] objids = items.split(",");
		for (int i = 0; i < objids.length; i++) {		
			guaranteeManager.removeById(objids[i]);
		}
		this.responseOutWithJson("{\"success\":true,\"msg\":\"删除成功\"}");
		return null;
	}

}
